<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<base href="${pageContext.request.scheme }://${pageContext.request.serverName}:
${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
<html>
<head>
	<meta charset="UTF-8">
	<title>图书管理</title>
	<link type="text/css" rel="stylesheet" href="static/css/style.css" >
</head>
<body>
	<div id="header">
			<img class="logo_img" alt="" src="../static/img/logo.gif" >
			<span class="wel_word">图书管理</span>
			<div>
				${sessionScope.msg}
				${pageContext.session.removeAttribute("msg")}
				<a href="manager.jsp">返回主页</a>
				<a href="UserServlet?way=doLogout">退出</a>
			</div>
	</div>
	
	<div id="main">
		<table>
			<tr>
				<td>名称</td>
				<td>价格</td>
				<td>作者</td>
				<td>销量</td>
				<td>库存</td>
				<td colspan="2">操作</td>
			</tr>

<%--	获取request中的list集合，用c标签的foreach遍历，展示到浏览器		--%>
			<c:forEach items="${page.list}" var="book" >
				<tr>
					<td>${book.title}</td>
					<td>${book.price}</td>
					<td>${book.author}</td>
					<td>${book.sales}</td>
					<td>${book.stock}</td>
					<td><a href="BookServlet?way=getBookById&id=${book.id}&pageNo=${page.pageNo}">修改</a></td>
					<td><a href="JavaScript:void(0)" onclick="deleteBookById(${book.id},'${book.title}')">删除</a></td>
				</tr>
				<script>
					function deleteBookById(id,title) {
						if(confirm("你确定要删除"+"【"+title+"】吗？")){
							window.location.href="BookServlet?way=deleteBookById&id="+id+"&title="+title+"&pageNo="+${page.pageNo};
						}
					}
				</script>

			</c:forEach>

<%--将添加和修改用到一个方法里面去，区分添加还是修改，在servlet里获取bookID，有得话就是修改，要将要修改的数据展示出来--%>
			

			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td><a href="BookServlet?way=getBookById&id=${book.id}&pageNo=${page.pageNo}">添加图书</a></td>

			</tr>	
		</table>
		<div id="page_nav">
		<%--	对首页，上一页进行限定，（获取当前页码）如果处于第一页，点不了首页，上一页		--%>
			<c:if test="${page.pageNo<=1}">
				<a href="JavaScript:void(0)">首页</a>
				<a href="JavaScript:void(0)">上一页</a>
			</c:if>
			<c:if test="${page.pageNo>1}">
				<a style="color: blue" href="BookServlet?way=getBookList&pageno=1"}>首页</a>
				<a style="color: blue" href="BookServlet?way=getBookList&pageno=${page.pageNo-1}">上一页</a>
			</c:if>
			<%--	对末页，下一页进行限定，（获取当前页码）如果处于最后一页，点不了末叶，下一页		--%>

			<c:if test="${page.pageNo>=page.totalPageNo}">
				<a href="JavaScript:void(0)">下一页</a>
				<a href="JavaScript:void(0)">末页</a>
			</c:if>

			<c:if test="${page.pageNo<page.totalPageNo}">
				<a style="color: blue" href="BookServlet?way=getBookList&pageno=${page.pageNo+1}">下一页</a>
				<a style="color: blue" href="BookServlet?way=getBookList&pageno=${page.totalPageNo}">末页</a>
			</c:if>

			||当前页：【${page.pageNo}】||总页数：【${page.totalPageNo}】




		</div>
	</div>
	
	<div id="bottom">
	</div>
</body>



</html>